<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>文章列表--layui后台管理模板</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="../../js/layui/css/layui.css" media="all" />
<script src="../../js/layui/layui.js"></script>
<link rel="stylesheet" href="../../css/font_eolqem241z66flxr.css"
	media="all" />
<link rel="stylesheet" href="../../css/news.css" media="all" />
</head>
<script type="text/html" id="barDemo">
			
			<a class="layui-btn layui-btn-sm" lay-event="edit" ><i class="layui-icon layui-icon-edit"></i>编辑</a>
			<a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
		</script>
<body class="childrenBody">
	<blockquote class="layui-elem-quote news_search">
		<div class="layui-form-item"
			style="margin-top: 10px; margin-left: 10px">
			<form class="layui-form" method="post" onsubmit="return false;">
				<label class="layui-form-mid">新闻名:</label>
				<div class="layui-input-inline" style="width: 100px;">
					<input type="text" id="proName" name="proName" placeholder="请输入新闻名"
						autocomplete="off" class="layui-input">
				</div>
				<label class="layui-form-mid">日期:</label>
				<div class="layui-input-inline" style="width: 100px;">
					<input type="text" name="min" id="min" placeholder="输入开始日期"
						autocomplete="off" class="layui-input">
				</div>
				<label class="layui-form-mid">--</label>
				<div class="layui-input-inline" style="width: 100px;">
					<input type="text" name="max" id="max" placeholder="输入截止日期"
						autocomplete="off" class="layui-input">
				</div>
				<label class="layui-form-mid">新闻类型：</label>
				<div class="layui-input-inline" style="width: 100px;">
					<select id="ntId" name="proRecommend">
						<option value="">请选择</option>

					</select>
				</div>
				<div class="layui-input-inline" style="width: 100px;">
					<button class="layui-btn" id="search" data-type="reload">搜索</button>

				</div>
				<div class="layui-inline">
					<a class="layui-btn layui-btn-normal newsAdd_btn">添加</a>
				</div>

				<div class="layui-inline">
					<a class="layui-btn layui-btn-danger batchDel">批量删除</a>
				</div>
			</form>

		</div>

	</blockquote>
	<div class="layui-form news_list">
		<table class="layui-table" id="news" lay-filter="table">

		</table>
	</div>
	<!-- <script type="text/javascript" id="choice">
	
	</script> -->

	<script type="text/javascript">
		layui
				.use(
						[ 'table', 'layer', 'form', 'laydate' ],
						function() {
							var table = layui.table, $ = layui.$, layer = layui.layer, form = layui.form, laydate = layui.laydate;
							laydate.render({
								elem : '#min' //指定元素
							});
							laydate.render({
								elem : '#max' //指定元素
							});
							table
									.render({
										elem : '#news',

										url : '../../../NewsServlet?reqName=selectNewsAll' //数据接口
										,
										page : true,
										cols : [ [ //表头

										{
											type : 'checkbox'
										}, {
											field : 'nId',
											title : '编号',
											width : 130,
											sort : true
										}, {
											field : 'nTitle',
											title : '标题',
											width : 150
										}, {
											field : 'nChoice',
											title : '是否精选',
											width : 150,
											hide : true
										}, {
											field : 'nContent',
											title : '内容',
											hide : true,
											width : 150
										}, {
											field : 'nDetails',
											title : '详情',
											width : 150,
											hide : true
										}, {
											field : 'ntName',
											title : '类型名称',
											hide : true,
											width : 150
										}, {
											field : 'ntId',
											title : '类型名称',
											hide : true,
											width : 150
										}, {
											field : 'nTime',
											title : '发布时间',
											width : 150
										}, {
											field : 'nClick',
											title : '点击量',
											width : 150,
											sort : true

										}, {
											field : 'ntName',
											title : '新闻类型',
											width : 150,

										},

										{
											title : '操作',
											align : 'center',
											fixed : 'right',
											width : 300,
											toolbar : '#barDemo'
										}

										] ],
										id : "NewsReload"
									});
							$.post("../../../SelectServlet?reqName=selectNewsTypeAll",
									function(res) {
								 
									  if (res!=null) {
										  
										$("#ntId").empty();
										$("#ntId").append(new Option("请选择", ""));
										$.each(res,function(index, item) {
											$("#ntId").append(new Option(item.ntName,item.ntId));
											
											});
									} else {
										
										$("#ntId").append(new Option("暂无数据", ""));
									}
									 
									  form.render();
								}, "json");
							$("#search")
									.click(
											function() {
												table
														.reload(
																'NewsReload',
																{
																	url : '../../../NewsServlet?reqName=selectNewsAll',
																	page : {
																		curr : 1
																	//重新从第 1 页开始
																	},
																	where : {
																		proName : $(
																				"#proName")
																				.val(),
																		min : $(
																				"#min")
																				.val(),
																		max : $(
																				"#max")
																				.val(),
																		isTui : $(
																				"#ntId")
																				.val()
																	}
																});
											});
							table
									.on(
											'tool(table)',
											function(obj) {
												var data = obj.data; //获得当前行数据
												var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
												var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
												sessionStorage.setItem("News",
														JSON.stringify(data));
												if (layEvent === 'del') { //删除
													
													layer
															.confirm(
																	'真的删除行么',
																	function(
																			index) {
																		obj
																				.del(); 
																		layer
																				.close(index);
																		$
																				.post(
																						"../../../NewsServlet?reqName=deleteNews",
																						{
																							id : data.nId
																						},
																						function(
																								res) {
																							if (res) {
																								layer
																										.msg(
																												'删除成功',
																												{
																													icon : 1,
																													time : 1500
																												});
																							} else {
																								layer
																										.msg(
																												'删除失败',
																												{
																													icon : 2,
																													time : 1500
																												});
																							}

																						},
																						"text")
																	});
												} else if (layEvent === 'edit') { //编辑
													var id = data.dId;

													var index = layui.layer
															.open({
																title : "编辑新闻",
																type : 2,
																content : "newsUpdate.html",
																success : function(
																		layero,
																		index) {
																	layui.layer
																			.tips(
																					'点击此处返回新闻列表',
																					' .layui-layer-close',
																					{
																						tips : 3
																					});
																},
																end : function() {
																	location
																			.reload();
																}
															})

													$(window)
															.resize(
																	function() {
																		layui.layer
																				.full(index);
																	})
													layui.layer.full(index);

												}
											});
							$(".newsAdd_btn").click(
									function() {
										var index = layui.layer.open({
											title : "添加新闻资讯",
											type : 2,
											content : "newsAdd.html",
											success : function(layero, index) {
												layui.layer.tips('点击此处返回新闻列表',
														' .layui-layer-close',
														{
															tips : 3
														});
											},
											end : function() {
												location.reload();
											}
										})
										$(window).resize(function() {
											layui.layer.full(index);
										})
										layui.layer.full(index);
									})
						})
	</script>
</body>
</html>